package bintree.leetcode;

public class Num110 {
    //平衡二叉树高度差不大于1
    public boolean isBalanced(TreeNode root) {
        if (root == null){
            return true;
        }
        int left = height(root.left);
        int right = height(root.right);
        int abs = Math.abs((left-right));
        return abs<=1&&isBalanced(root.left)&&isBalanced(root.right);

    }
    public int height(TreeNode root){
        return  root == null?0:1+Math.max(height(root.left),height(root.right));
    }
}
